﻿<UserControl x:Class="StackHash.EventList"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vcs="clr-namespace:StackHash.ValueConverters"
    xmlns:local="clr-namespace:StackHash" Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="MasterResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <UserControl.CommandBindings>
        <CommandBinding Command="Properties" x:Name="commandBindingProperties" CanExecute="commandBindingProperties_CanExecute" Executed="commandBindingProperties_Executed" />
    </UserControl.CommandBindings>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" MinWidth="50" x:Name="Column1" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" MinWidth="50" x:Name="Column3" />
        </Grid.ColumnDefinitions>
        
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <TextBlock Margin="6,6,0,6" FontSize="14" FontWeight="Bold" HorizontalAlignment="Left">
                <TextBlock>
                    <Hyperlink IsEnabled="{Binding NotBusy}" Name="linkMappedProducts" Click="linkMappedProducts_Click">Mapped Products</Hyperlink>
                </TextBlock>
                <TextBlock>&gt;</TextBlock>
                <TextBlock Text="{Binding EventListTitle}" />
            </TextBlock>

            <StackPanel Margin="0,6,6,6" Grid.Column="1"  Orientation="Horizontal" HorizontalAlignment="Right" Name="stackPanelPageNavigation">
                <Rectangle Width="1" Stroke="LightGray" />
                <Button Style="{StaticResource ToolBarButtonStyle}" Name="buttonFirstPage" Click="buttonFirstPage_Click" ToolTip="Go to the first page of events.">
                    <Image Source="Help\first.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Button Style="{StaticResource ToolBarButtonStyle}" Name="buttonPrevPage" Click="buttonPrevPage_Click" ToolTip="Go to the previous page of events.">
                    <Image Source="Help\prev.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <TextBlock Margin="6,0,6,0" FontSize="14" FontWeight="Bold">
                    <TextBlock>Page</TextBlock>
                    <TextBlock Text="{Binding CurrentEventsPage, Converter={StaticResource intGeneralDisplayConverter}}" />
                    <TextBlock>of</TextBlock>
                    <TextBlock Text="{Binding CurrentEventsMaxPage, Converter={StaticResource intGeneralDisplayConverter}}" />
                </TextBlock>
                <Button Style="{StaticResource ToolBarButtonStyle}" Name="buttonNextPage" Click="buttonNextPage_Click" ToolTip="Go to the next page of events.">
                    <Image Source="Help\next.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Button Style="{StaticResource ToolBarButtonStyle}" Name="buttonLastPage" Click="buttonLastPage_Click" ToolTip="Go to the last page of events.">
                    <Image Source="Help\last.png" Style="{StaticResource ButtonImageStyle}" />
                </Button>
                <Rectangle Width="1" Stroke="LightGray" />
            </StackPanel>

        </Grid>
        
        <ListView Margin="6" Grid.Row="1" ItemsSource="{Binding EventPackages}" GridViewColumnHeader.Click="listViewEventsHeader_Click" SelectionChanged="listViewEvents_SelectionChanged" ContextMenuOpening="listViewEvents_ContextMenuOpening" Name="listViewEvents" MouseDoubleClick="listViewEvents_MouseDoubleClick" SelectionMode="Single">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Open Event Page on WinQual." Name="menuitemOpenEventPage" Click="menuitemOpenEventPage_Click" />
                    <MenuItem Header="Send Event to Plugin" ItemsSource="{Binding ActivePlugins}" Name="menuItemSendEventToPlugin" Click="menuItemSendEventToPlugin_Click">
                        <MenuItem.ItemContainerStyle>
                            <Style TargetType="{x:Type MenuItem}">
                                <Setter Property="Header" Value="{Binding Name}" />
                                <Setter Property="Tag" Value="{Binding}" />
                            </Style>
                        </MenuItem.ItemContainerStyle>
                    </MenuItem>
                    <MenuItem Header="Copy Event URL to Clipboard" Name="menuItemCopyEventUrl" Click="menuItemCopyEventUrl_Click" />
                    <Separator />
                    <MenuItem Command="local:StackHashCommands.ExportCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon">
                        <MenuItem.Icon>
                            <Image Source="Help\export.png" />
                        </MenuItem.Icon>
                        <MenuItem Command="local:StackHashCommands.ExportProductListCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                        <MenuItem Command="local:StackHashCommands.ExportEventListCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                        <MenuItem Command="local:StackHashCommands.ExportEventListFullCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                    </MenuItem>
                    <MenuItem Command="local:StackHashCommands.ExtractAllCabsCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" IsEnabledChanged="MenuItem_IsEnabledChangedDimIcon" />
                    <Separator Name="separatorBeforeRefresh" />
                    <MenuItem Command="Properties" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                    <Separator />
                    <MenuItem Command="local:StackHashCommands.RefreshCommand" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
                </ContextMenu>
            </ListView.ContextMenu>
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="100">
                        <GridViewColumnHeader Tag="Id" Content="ID" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Id}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="100">
                        <GridViewColumnHeader Tag="WorkFlowStatusName" Content="Status" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Control x:Name="ReferenceStatusCell">
                                    <Control.Template>
                                        <ControlTemplate>
                                            <TextBlock Text="{Binding WorkFlowDisplayMapping.Name}" HorizontalAlignment="Left" />
                                        </ControlTemplate>
                                    </Control.Template>
                                </Control>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}}" Value="True">
                                        <Setter TargetName="ReferenceStatusCell" Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate>
                                                    <ComboBox SelectedItem="{Binding WorkFlowDisplayMapping}" ItemsSource="{Binding AvailableWorkFlowDisplayMappings}" DisplayMemberPath="Name" Margin="0" Padding="3,0" BorderThickness="0" Name="comboBoxStatus" SelectionChanged="comboBoxStatus_SelectionChanged" IsEditable="False" />
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="100">
                        <GridViewColumnHeader Tag="BugId" Content="Reference" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Control x:Name="ReferenceCell">
                                    <Control.Template>
                                        <ControlTemplate>
                                            <TextBlock Text="{Binding BugId}" HorizontalAlignment="Left" />
                                        </ControlTemplate>
                                    </Control.Template>
                                </Control>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}}" Value="True">
                                        <Setter TargetName="ReferenceCell" Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate>
                                                    <TextBox Text="{Binding BugId, Mode=OneWay}" Margin="0" Padding="0" BorderThickness="0" Name="textBoxReference" LostFocus="textBoxReference_LostFocus" KeyDown="textBoxReference_KeyDown" Loaded="textBoxReference_Loaded" />
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="125">
                        <GridViewColumnHeader Tag="PlugInBugId" Content="Plugin Reference" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding PlugInBugId}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="125">
                        <GridViewColumnHeader Tag="EventTypeName" Content="Type" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding EventTypeName}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="75">
                        <GridViewColumnHeader Tag="TotalHits" Content="Hits" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding TotalHits, Converter={StaticResource intGeneralDisplayConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="75">
                        <GridViewColumnHeader Tag="CabCount" Content="Cabs" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding CabCount, Converter={StaticResource intGeneralDisplayConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="125">
                        <GridViewColumnHeader Tag="ApplicationName" Content="App" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ApplicationName}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="100">
                        <GridViewColumnHeader Tag="ApplicationVersion" Content="App Version" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ApplicationVersion}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="100">
                        <GridViewColumnHeader Tag="ModuleName" Content="Module" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ModuleName}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="125">
                        <GridViewColumnHeader Tag="ModuleVersion" Content="Module Version" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ModuleVersion}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="125">
                        <GridViewColumnHeader Tag="ExceptionCode" Content="Exception Code" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ExceptionCode, Converter={StaticResource longHexDisplayConverter}, ConverterParameter=8}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="150">
                        <GridViewColumnHeader Tag="ExceptionCode" Content="Exception Message" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ExceptionMessage}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="100">
                        <GridViewColumnHeader Tag="Offset" Content="Offset" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Offset, Converter={StaticResource longHexDisplayConverter}, ConverterParameter=0}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="130">
                        <GridViewColumnHeader Tag="ApplicationTimeStamp" Content="App Link Date" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ApplicationTimeStamp, Converter={StaticResource dateTimeDisplayConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="130">
                        <GridViewColumnHeader Tag="ModuleTimeStamp" Content="Module Link Date" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding ModuleTimeStamp, Converter={StaticResource dateTimeDisplayConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="130">
                        <GridViewColumnHeader Tag="DateCreatedLocal" Content="Event Created" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DateCreatedLocal, Converter={StaticResource dateTimeDisplayConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="130">
                        <GridViewColumnHeader Tag="DateModifiedLocal" Content="Event Modified" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DateModifiedLocal, Converter={StaticResource dateTimeDisplayConverter}}" HorizontalAlignment="Right" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Width="150">
                        <GridViewColumnHeader Tag="" Content="Cab Collection Policy" />
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding CabCollectionPolicy, Converter={StaticResource cabCollectionPolicyDisplayConverter}}" HorizontalAlignment="Left" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        <GridSplitter Grid.Column="1" Grid.RowSpan="2" Margin="0,6,0,6" ResizeBehavior="PreviousAndNext" Width="3" />
        <TextBlock Grid.Column="2" Margin="6" FontSize="14" FontWeight="Bold" Visibility="{Binding ElementName=listViewEvents, Path=SelectedItem, Converter={StaticResource nullVisibleConverter}}">&lt; Select Event</TextBlock>
        <TextBlock Grid.Column="2" Margin="6" FontSize="14" FontWeight="Bold" Visibility="{Binding ElementName=listViewEvents, Path=SelectedItem, Converter={StaticResource nullHiddenConverter}}">
            <TextBlock Text="{Binding ElementName=listViewEvents, Path=SelectedItem.Id}" />
            <TextBlock>: <Hyperlink IsEnabled="{Binding NotBusy}" Name="linkShowDetails" Click="linkShowDetails_Click">Show Details</Hyperlink></TextBlock>
        </TextBlock>
        <DockPanel Margin="3" Grid.Row="1" Grid.Column="2">
            <ScrollViewer Margin="6" DockPanel.Dock="Top" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto">            
                <local:SummaryControlProduct DataContext="{Binding CurrentProduct}" HorizontalAlignment="Left" />
            </ScrollViewer>
            <ScrollViewer Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" Margin="0,6,6,6" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" DockPanel.Dock="Top">
                <WrapPanel Orientation="Horizontal" Margin="0">
                    <local:PieChartControl x:Name="pieChartOs" ChartTitle="Hits / Operating System" SegmentDoubleClick="pieChartOs_SegmentDoubleClick" />
                    <local:PieChartControl x:Name="pieChartLang" ChartTitle="Hits / Language" SegmentDoubleClick="pieChartLang_SegmentDoubleClick" />
                    <local:DateBarChartControl x:Name="dateChartHits" ChartTitle="Hits / Date" IsProductPageChart="False"  SearchForDate="dateChartHits_SearchForDate" />
                </WrapPanel>
            </ScrollViewer>
        </DockPanel>
    </Grid>
</UserControl>
